home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Magazine / PC2Amiga / Samba / examples / misc / wall.perl < prev   
Text File  |  1996-05-04  |  2KB  |  70 lines

  1. #!/usr/local/bin/perl
  2. #@(#) smb-wall.pl Description:
  3. #@(#) A perl script which allows you to announce whatever you choose to
  4. #@(#) every PC client currently connected to a Samba Server...
  5. #@(#) ...using "smbclient -M" message to winpopup service.
  6. #@(#) Default usage is to message every connected PC.
  7. #@(#) Alternate usage is to message every pc on the argument list.
  8. #@(#)  Hacked up by Keith Farrar <farrar@parc.xerox.com>
  9. #
  10. # Cleanup and corrections by
  11. # Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
  12. # Message to send can be now also fed (quietly) from stdin; a pipe will do.
  13. #=============================================================================
  14.  
  15. $smbstatus = "/usr/local/bin/smbstatus";
  16. $smbshout = "/usr/local/bin/smbclient -M";
  17.  
  18. if (@ARGV) {
  19.     @clients = @ARGV;
  20.     undef @ARGV;
  21. }
  22. else {  # no clients specified explicitly
  23.     open(PCLIST, "$smbstatus |") || die "$smbstatus failed!.\n$!\n";
  24.     while(<PCLIST>) {
  25.     last if /^Locked files:/;
  26.     split(' ', $_, 6);
  27.         # do not accept this line if less then six fields
  28.         next unless $_[5];
  29.         # if you have A LOT of clients you may speed things up by
  30.         # checking pid - no need to look further if this pid was already
  31.         # seen;  left as an exercise :-)
  32.         $client = $_[4];
  33.     next unless $client =~ /^\w+\./;       # expect 'dot' in a client name
  34.     next if grep($_ eq $client, @clients); # we want this name once
  35.     push(@clients, $client);
  36.     }
  37.     close(PCLIST);
  38. }
  39.  
  40. if (-t) {
  41.     print <<'EOT';
  42.  
  43. Enter message for Samba clients of this host
  44. (terminated with single '.' or end of file):
  45. EOT
  46.  
  47.     while (<>) {
  48.     last if /^\.$/;
  49.     push(@message, $_);
  50.     }
  51. }
  52. else { # keep quiet and read message from stdin
  53.     @message = <>;
  54. }
  55.  
  56. foreach(@clients) {
  57. ##    print "To $_:\n";
  58.     if (open(SENDMSG,"|$smbshout $_")) {
  59.     print SENDMSG @message;
  60.     close(SENDMSG);
  61.     }
  62.     else {
  63.     warn "Cannot notify $_ with $smbshout:\n$!\n";
  64.     }
  65. }
  66.  
  67. exit 0;
  68.  
  69.